<!-- 邮寄管理 -->
<template>
  <div class="mod-config">
    <el-button-group style="margin-bottom: 10px;">
      <el-button type="primary" icon="el-icon-search" @click="searchHandle">查找</el-button>
      <el-button type="primary" icon="el-icon-delete" @click="searchReset">清空</el-button>
      <el-button type="primary" icon="el-icon-plus" @click="addHandle()">新增邮寄信息</el-button>
    </el-button-group>
    <el-form inline label-width="100px" @keyup.enter.native="searchHandle">
      <el-form-item label="配镜单号">
        <el-input v-model="dataForm.saleBillId"></el-input>
      </el-form-item>
      <el-form-item label="会员卡号">
        <el-input v-model="dataForm.customerCard"></el-input>
      </el-form-item>
      <el-form-item label="顾客姓名">
        <el-input v-model="dataForm.name"></el-input>
      </el-form-item>
      <el-form-item label="顾客电话">
        <el-input v-model="dataForm.phone1"></el-input>
      </el-form-item>
      <el-form-item label="快递单号">
        <el-input v-model="dataForm.expressCode"></el-input>
      </el-form-item>
      <el-form-item label="邮寄日期">
        <el-row>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.expressTime" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
          <el-col class="line" :span="2" style="text-align: center;">-</el-col>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.takeMirroTimeMax" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="邮寄状态">
        <el-select v-model="value" placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div class="avue-crud">
      <el-table :data="dataList" border v-loading="dataListLoading" :max-height="tableHeight">
        <el-table-column prop="saleBillId" label="配镜单号"></el-table-column>
        <el-table-column prop="customerCard" label="会员卡号"></el-table-column>
        <el-table-column prop="name" label="顾客姓名"></el-table-column>
        <el-table-column prop="phone1" label="顾客电话"></el-table-column>
        <el-table-column prop="expressCode" label="快递单号"></el-table-column>
        <el-table-column prop="expressTime" label="邮寄日期"></el-table-column>
        <el-table-column label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button v-if="permissions.eims_inventoryapply_add" type="text" icon="el-icon-edit" @click="addHandle(scope.row.id)">邮寄</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="avue-crud__pagination">
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next"></el-pagination>
    </div>

    <table-form v-if="addVisible" ref="add" @refreshDataList="getDataList"></table-form>
    <table-form v-if="updateVisible" ref="update" @refreshDataList="getDataList"></table-form>
  </div>
</template>

<script>
  import { mapGetters } from "vuex"
  import { expressFetchList, expressIdAdd } from "@/api/eims/express.js";
  import tableForm from "./form"
  
  export default {
    data() {
      return {
        options: [{
            value: "hasExpress",
            label: "已邮寄"
          },
          {
            value: "notExpress",
            label: "未邮寄"
          }
        ],
        value: "",
        dataForm: {},
        dataList: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        addVisible: false,
        updateVisible: false,
        searchForm: {
          saleId: "",
          customerName: "",
          deptId: ""
        }
      };
    },
    created() {
      this.getDataList();
    },
    components: {
      tableForm
    },
    computed: {
      ...mapGetters(["permissions"]),
      tableHeight: function(){
        return window.innerHeight - 260
      }
    },
    methods: {
      //  查询数据
      searchHandle() {
        this.pageIndex = 1
        this.getDataList()
      },
      // 清空搜索框
      searchReset() {
        this.dataForm = {};
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true;
        let params = {
          current: this.pageIndex,
          size: this.pageSize
        };
        expressFetchList(Object.assign(params, this.dataForm)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false;
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.getDataList();
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.getDataList();
      },
      // 新增邮寄信息
      addHandle(id) {
        this.addVisible = true;
        this.$nextTick(() => {
          this.$refs.add.init(id);
        });
      },
      // 填写邮寄单号
      updateHandle(id) {
        this.updateVisible = true;
        this.$nextTick(() => {
          this.$refs.update.init(id);
        });
      }
    }
  };
</script>
<style>
</style>
